//
//  LLTableViewCell.swift
//  新浪微博
//
//  Created by mac on 16/5/24.
//  Copyright © 2016年 mac.com. All rights reserved.
//

import UIKit
import SnapKit
class LLTableViewCell: UITableViewCell {
    //约束对象属性
    var toolBarTopCon: Constraint?
    var statu: LLStatusViewModel? {
        didSet {
        statusOrighinalView.status = statu
        statusToolBar.statusViewModel = statu
         toolBarTopCon?.uninstall()
            if  statu?.status?.retweeted_status == nil{
            //设置数据
            statusRetweetedView.statusViewModel = nil
            //隐藏微博
            statusRetweetedView.hidden = true
            //更新约束 底部工具条的顶部应该相对于 原创微博底部
            statusToolBar.snp_updateConstraints(closure: { (make) in
                self.toolBarTopCon = make.top.equalTo(statusOrighinalView.snp_bottom).constraint
                })
            }else{
                //设置数据
                statusRetweetedView.statusViewModel = statu
                //显示微博
                statusRetweetedView.hidden = false
                //更新约束 底部工具条的顶部应该相对于 原创微博底部
                statusToolBar.snp_updateConstraints(closure: { (make) in
                    self.toolBarTopCon = make.top.equalTo(statusRetweetedView.snp_bottom).constraint
                })

            
            }
            
        }
    }
   
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
//        self.backgroundColor = randomColor()
//        self.selectionStyle = .None
        self.selectionStyle = .None
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setupUI() {
        contentView.backgroundColor = UIColor(white: 240 / 255, alpha: 1)
        contentView.addSubview(statusOrighinalView)
        contentView.addSubview(statusRetweetedView)
        contentView.addSubview(statusToolBar)
        //设置约束
        statusOrighinalView.snp_makeConstraints { (make) in
            make.top.right.left.equalTo(self.contentView)
        }
        statusRetweetedView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(statusOrighinalView.snp_bottom)
            make.right.left.equalTo(self.contentView)
        }
        statusToolBar.snp_makeConstraints { (make) -> Void in
           self.toolBarTopCon = make.top.equalTo(statusRetweetedView.snp_bottom).constraint
            make.right.left.equalTo(self.contentView)
            make.height.equalTo(36)
        }
        //给cell的contentView的底部添加约束
        //snp --> 取消了视图的frame 布局
        contentView.snp_makeConstraints { (make) in
            //将contentView的约束都加上
            make.top.left.right.equalTo(self)
            make.bottom.equalTo(statusToolBar.snp_bottom)
        }

    }
    //懒加载子视图
    //原创微博视图
    private lazy var statusOrighinalView: LLStatusOriginalView = LLStatusOriginalView()
//    private lazy var statusOriginalView: LLStatusOriginalView = LLStatusOriginalView()
    //转发微博视图
    private lazy var statusRetweetedView: LLStatusRetweetedView = LLStatusRetweetedView()

    //底部工具条视图
    private var statusToolBar:LLStatusToolBar = LLStatusToolBar()
    
    
    
}
